<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="/css/ui-lightness/jquery-ui-1.8.18.custom.css" type="text/css" />
<script type="text/javascript" src="/admin/js/plugins/jquery-1.7.min.js"></script>
<script type="text/javascript" src="/admin/js/plugins/jquery-ui-1.8.16.custom.min.js"></script>
<title>Insert title here</title>
<script type="text/javascript">
<!--
jQuery(document).ready(function () {
	/* var abc = "hello";
	var txt = "hello the world";
	//alert(txt.replace(/^(he)+/, ""));
	alert(txt.replace(new RegExp("^("+abc+")+"), "")); */
	
	var keywords = "";
	var getAjax = false;
	var cache = {};
	jQuery( "input[name=name]" ).autocomplete({
		minLength: 2,
		source: function( request, response ) {
			var term = request.term;
			/* if (keywords == "") {
				keywords = term;
				getAjax = true;
			} else {
				var len = term.replace(new RegExp("^("+keywords+")+"), "").length;
				if (term.length == len) {
					getAjax = true;
					keywords = term;
				} else {
					//getAjax = false;
				}
			} */
			
			jQuery.ajax({
				url: "http://localhost:8888/ajax/deal",
				dataType: "json",
				data: {keywords: term},
				success: function( data ) {
					cache = data;
					// Therefore, convert it to a real array
					response( jQuery.map( cache, function( value , label) {
						return {
							label: label,
							value: label,
							code: value
						}
					}));
				}
			});
		},
		select: function( event, ui ) {
			jQuery("input[name=code]").val(ui.item.code);
		}
	});
});
//-->
</script>
</head>
<body>
<form action="" method="post">
<table>
	<tr>
		<td>Name</td>
		<td><input type="text" name="name"></td>
	</tr>
	<tr>
		<td>Code</td>
		<td><input type="text" name="name"></td>
	</tr>
</table>
<button type="submit">abc</button>
</form>
</body>
</html>